<template>
  <jke-modal
      :visible.sync="jkeForm.visible"
      :width="1200"
      :title="jkeForm.title"
      :fullscreen.sync="jkeForm.fullscreen"
      :switchFullscreen="jkeForm.switchFullscreen"
    >
    <!--  -->
    <crumbs @goBack="goBack" :superiorMenu="['生产管理','领料单']" currentMenu="领料详情">
    </crumbs>
    <div class="uni-card">
      <div class="bd-line"></div>
      <div class="item-wrap1">
        <div class="detail-item" style="width: 20%">
          <p class="subtitle">申请单号</p>
          <p class="secondary-text">{{ detailInfo.applyNo || '-' }}</p>
        </div>
        <div class="detail-item" style="width: 20%">
          <p class="subtitle">提交人</p>
          <p class="secondary-text">{{ detailInfo.applicantIdText || '-' }}</p>
        </div>
        <div class="detail-item" style="width: 20%">
          <p class="subtitle">提交时间</p>
          <p class="secondary-text">{{ detailInfo.applyTime || '-' }}</p>
        </div>
        <!-- <div class="detail-item" style="width: auto">
          <p class="subtitle" style="text-align:right">状态</p>
          <p class="secondary-text" :style="{color: setColor(detailInfo.outStockStatus), fontSize: '16px'}">
            {{ detailInfo.outStockStatus == '1' ? '未开始' : detailInfo.outStockStatus == '2' ? '进行中' : '已完成' }}</p>
        </div> -->
        <div class="detail-item" style="width: auto">
          <flow-status ids="MESS_RECEIVE_MATERIAL_APPLY" style="text-align:right"
            :formStatusText="detailInfo.outStockStatus == '1' ? '未开始' : detailInfo.outStockStatus == '2' ? '进行中' : '已完成'" :flowStatusText="detailInfo.flowStatusName"
            :flowStatus="detailInfo.flowStatus"></flow-status>
        </div>
      </div>
    </div>
    <div class="cards-box">
      <a-card title="基本信息" :bordered="false" style="margin-top:12px">
        <div class="item-wrap">
          <div class="detail-item">
            <p class="subtitle">工单编号</p>
            <p class="secondary-text">{{ detailInfo.orderCode || '-' }}</p>
          </div>
          <div class="detail-item">
            <p class="subtitle">生产产品</p>
            <p class="secondary-text">{{ detailInfo.goodsFullName || '-' }}</p>
          </div>
          <div class="detail-item">
            <p class="subtitle">规格</p>
            <p class="secondary-text">{{ detailInfo.spec || '-' }}</p>
          </div>
        </div>
        <div class="item-wrap">
          <div class="detail-item">
            <p class="subtitle">领料人</p>
            <p class="secondary-text">{{ detailInfo.reciverIdText || '-' }}</p>
          </div>
          <div class="detail-item">
            <p class="subtitle">基本单位</p>
            <p class="secondary-text">{{ detailInfo.basicUnitText || '-' }}</p>
          </div>
          <div class="detail-item" />
        </div>
        <div class="item-wrap">
          <div class="detail-item">
            <p class="subtitle">领用时间</p>
            <p class="secondary-text">{{ detailInfo.receiveTime || '-' }}</p>
          </div>
          <div class="detail-item" />
          <div class="detail-item" />
        </div>
      </a-card>
      <a-card title="领用物料" :bordered="false" style="margin-top:12px">
        <a-table :columns="goodsTable.columns" :data-source="goodsTable.dataSource" :pagination="false">
        </a-table>
      </a-card>
      <a-card title="其他信息" :bordered="false" style="margin-top:12px">
        <div class="item-wrap">
          <div class="detail-item" style="width:100%">
            <p class="subtitle">备注</p>
            <p class="secondary-text">{{ detailInfo.remark || '-' }}</p>
          </div>
        </div>
        <div class="item-wrap" style="margin-top:40px">
          <div style="width:100%">
            <p class="subtitle">附件</p>
            <file-detail :ids="detailInfo.attachment"></file-detail>
          </div>
        </div>
      </a-card>
      <div style="margin-top: 12px" v-if="detailInfo.flowInstId">
        <Examine  type="2" :id="detailInfo.flowInstId" ref="examine" />
        <div style="height: 50px"></div>
      </div>
    </div>
  </jke-modal>
</template>
<script>
import crumbs from '@/components/crumbs.vue'
import FileDetail from '@/components/fileActions/FileDetail'
import Examine from '@/components/examine'
import { API } from '@/api/requestFzs'
import FlowStatus from '@/pubComponent/FlowStatus'
export default {
  data() {
    return {
      jkeForm: {
        title: '领料详情',
        visible: false,
        fullscreen: true,
        switchFullscreen: true,
      },
      detailInfo: {},
      flowStatus: {
        RUNNING: { text: '审批中', color: '#FF943E' },
        REFUSE: { text: '已拒绝', color: '#FF4D4F' },
        CANCELED: { text: '已撤回', color: '#888888' },
        AGREE: { text: '已通过', color: '#00B042' },
        TERMINATED: { text: '已终止', color: '#FF4D4F' },
      },
      goodsTable: {
        loading: false,
        dataSource: [],
        columns: [
          {
            title: '物料',
            width: '10%',
            key: 'goodsName',
            dataIndex: 'goodsName',
          },
          {
            title: '规格',
            width: '10%',
            key: 'goodsSpec',
            dataIndex: 'goodsSpec',
          },
          {
            title: '物料类型',
            width: '10%',
            key: 'goodsTypeText',
            dataIndex: 'goodsTypeText',
          },
          {
            title: '基本单位',
            width: '10%',
            key: 'goodsBasicUnitText',
            dataIndex: 'goodsBasicUnitText',
          },
          {
            title: '计划投料总量',
            width: '15%',
            key: 'planTotalNum',
            dataIndex: 'planTotalNum',
          },
          {
            title: '本次领料量',
            width: '15%',
            key: 'num',
            dataIndex: 'num',
          },
          {
            title: '已出库量',
            width: '15%',
            key: 'inOutBoundNum',
            dataIndex: 'inOutBoundNum',
          },
        ],
      },
    }
  },
  components: {
    crumbs,
    FileDetail,
    Examine,
    FlowStatus,
  },
  methods: {
    setColor(s) {
      let cor = {
        1: '#FF943E',
        2: '#1890FF',
        3: '#00B042',
      }
      return cor[s] || ''
    },
    /* 面包屑返回 */
    goBack() {
      let cuttentTab = this.$route.query.cuttentTab
      let activeTab = this.$route.query.activeTab
      if (cuttentTab) {
        let paramsObj = {
          id: this.$route.query.parentId,
          cuttentTab: cuttentTab,
        }
        this.$openWay(this, false, '/workOrderDetail', paramsObj)
      } else if (activeTab) {
        this.$router.replace({
          path: '/stockTask',
          query: {
            activeTab,
          },
        })
      } else {
        this.$router.go(-1)
      }
    },
    initDetail(id) {
      this.jkeForm.visible = true
      API.messReceiveMaterialApplyQueryById(id).then((res) => {
        if (res.code == 200) {
          this.detailInfo = res.result
          this.goodsTable.dataSource = res.result.infoVoList
        } else {
          this.$antdMessage.error(res.result)
        }
      })
    },
  },
}
</script>
<style scoped lang="less">
@import '~@/assets/less/public.less';
.item-wrap {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
}
.item-wrap1 {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
}
.item-wrap:nth-of-type(n + 2) {
  margin-top: 40px;
}
.detail-item {
  width: 30%;
}
.uni-card {
  padding: 24px 40px;
  margin: -12px -12px 0;
  background: #fff;
}
.bd-line {
  height: 1px;
  background: @greyBorder;
  margin: -12px -40px 24px -40px;
}
.cards-box {
  height: calc(100vh - 205px);
  overflow-y: scroll;
}
</style>
